<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>添加管理员</title>
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
</head>
    
<div>
<div class="z-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="userId" class="layui-form-label">
                <span class="x-red">*</span>用户ID
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userId" name="userId" required="" lay-verify="userId" class="layui-input"
                       maxlength="10" onkeyup="value=this.value.replace(/\D+/g,'')">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>为此用户添加管理员权限
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>状态
            </label>

            <div class="layui-input-inline" id="state" >
                <input type="radio"  name="state" value="有效" title="有效"  checked/>
                <input type="radio"  name="state" value="无效" title="无效" />
            </div>


        </div>

        <div class="layui-form-item">
           <label  class="layui-form-label">
                <span class="x-red">*</span>权限
            </label>
            <div class="layui-input-inline">
              <select id="power" name="power">
                <option value="">请选择权限</option>
                <%--<option value="超级管理员">超级管理员</option>--%>
                <option value="用户管理员">用户管理员</option>
                <option value="商品管理员">商品管理员</option>
                <option value="前台门户管理员">前台门户管理员</option>
                <option value="订单管理员">订单管理员</option>
                <option value="权限分配管理员">权限分配管理员</option>
                <option value="会员管理员">会员管理员</option>
                <option value="系统管理员">系统管理员</option>
              </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label"></label>
            <input id="add" type="button" class="layui-btn" value="增加">
        </div>
    </form>
</div>
</div>

<script type="text/javascript" >
    layui.use(['form','layer'], function(){
      $ = layui.jquery;
      var form = layui.form(),
      layer = layui.layer;


      //自定义验证规则
      form.verify({
        userId: function(value){
          if(value.length<=0){
            return '用户id不能为空';
          }
        }

      });


        //管理员添加
        $("#add").click(function() {
            var userId = $.trim($("#userId").val());
            var power = $.trim($("#power").val());
            var state= $.trim($('#state input:checked').val());
            console.log(userId);

            $.ajax({
                type: 'POST',
                url: '/power/addPower',
                dataType: "json",
                data: {uid:userId,power:power,state:state},
                error: function () {
                    alert("失败");
                },
                success: function (data) {
                    if(data.msg=="添加成功"){
                        alert("添加成功");
                    }
                    else if(data.msg=="管理员已存在"){
                        alert("管理员已存在！");
                    }else if(data.msg=="没有该用户"){
                        alert("没有该用户！");
                    }
                    location.reload();
                }
            });
        });
    });
</script>
</body>
</html>